package com.biz.primus.ms.commodity.dao.redis.extend;

import com.biz.primus.base.redis.CrudRedisDao;
import com.biz.primus.ms.commodity.dao.ro.ExtendRo;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * 商品扩展属性 RedisDao
 *
 * @author david-liu
 * @date 2017年01月04日
 * @reviewer
 * @see
 */
@Repository
public class ExtendRedisDao extends CrudRedisDao<ExtendRo, String> implements Serializable {

    private static final String CATEGORY_FIELD_NAME = "categoryId";


    public List<ExtendRo> findExtends(Long categoryId) {
        String extendsMappingCategorySortSetKey = getFieldSortedSetKey(CATEGORY_FIELD_NAME, categoryId);
        if (logger.isDebugEnabled()) {
            logger.debug("开始从分类[{}]获取商品过滤条件, 分类过滤条件SortedSetKey=[{}]", categoryId, extendsMappingCategorySortSetKey);
        }
        Set<byte[]> filterItemIdByteSet = zRange(extendsMappingCategorySortSetKey, 0, -1);

        if (logger.isDebugEnabled()) {
            logger.debug("从分类[{}]SortedSet中获取到了[{}]条数据", categoryId, filterItemIdByteSet.size());
            logger.debug("获取过滤条件结束");
        }
        return findByIds(filterItemIdByteSet);
    }

}
